package nes;

/**
 * Polar vector implementation.
 * 
 * @author Sergey Negrashov.
 * 
 */
public class PolarVector implements Comparable<PolarVector> {

  /**
   * Vector Magnitude.
   */
  private Double r;

  /**
   * Vector angle.
   */
  private Double theta;

  /**
   * Simple constructor creates a zero length vector.
   */
  public PolarVector() {
    r = (double) 0;
    theta = (double) 0;
  }

  /**
   * Construct a vector with passed parameters.
   * 
   * @param r distance vector.
   * @param theta angle component.
   */
  public PolarVector(double r, double theta) {
    this.r = r;
    this.theta = theta;
  }

  /**
   * Compare operation based only on the r component.
   * 
   * @param o vector to compare to.
   * @return 0 if the Objects are equivalent, negative number if the object is less then the object
   * being compared to and a positive number if the object is greater.
   */
  @Override
  public int compareTo(PolarVector o) {
    return r.compareTo(o.getR());
  }

  /**
   * Equality operation.
   * 
   * @param o object to be compared.
   * @return {@code true} if the objects are equal.
   */
  @Override
  public boolean equals(Object o) {
    if (!(o instanceof PolarVector)) {
      return false;
    }
    PolarVector vector = (PolarVector) o;
    return r.equals(vector.getR()) && theta.equals(vector.getTheta());
  }

  /**
   * Hash code operation.
   * 
   * @return the hashcode for the vector.
   */
  @Override
  public int hashCode() {
    return r.hashCode() ^ theta.hashCode();
  }

  /**
   * Getter for theta.
   * 
   * @return angle component.
   */
  public double getTheta() {
    return theta;
  }

  /**
   * Setter for theta.
   * 
   * @param theta angle to set.
   */
  public void setTheta(double theta) {
    this.theta = theta;
  }

  /**
   * Getter for R.
   * 
   * @return distance component.
   */
  public double getR() {
    return r;
  }

  /**
   * Setter for R.
   * 
   * @param r distance component to set.
   */
  public void setR(double r) {
    this.r = r;
  }

  /**
   * Return vector value in a string.
   * 
   * @return vector value string.
   */
  public String toString() {
    return "Vector: r=" + r.toString() + " theta=" + theta.toString();

  }
}
